import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
public class SmallChangeSys {
    //1、先完成显示菜单，并可以选菜单，给出对应提示
    //2、完成零钱通明细
    //3、完成收益入账
    public static void main(String[] args) {
        //定义变量
        boolean loop=true;
        Scanner scanner=new Scanner(System.in);
        String key="";
        String details="\n-------零钱通明细---------";
        double money=0;
        double balance=0;
        Date date=null;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String note="";
        do{
            System.out.println("====零钱通===");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退  出");
            System.out.println("请选择(1-4):");
            key=scanner.next();
            //使用switch分支
            switch (key){
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println("收益入账金蝶:");
                    money=scanner.nextDouble();
                    if(money<=0){
                        System.out.println("请输入>0的数字");
                        break;
                    }
                    balance+=money;
                    date=new Date();
                    System.out.println(sdf.format(date));

//拼接收益入账信息到details
                    details+="\n收益入账\t"+money+"\t"+sdf.format(date)+"\t"+balance;
                    System.out.println(details);

                    break;
                case "3":
                    System.out.println("消费金额：");
                    money=scanner.nextDouble();
                    //范围的校验
                    if(money<=0||money>balance){
                        System.out.println("消费金额应该在0-"+balance+"之间");
                        break;
                    }
                    System.out.println("请输入消费说明：");
                    note=scanner.next();
                    balance-=money;
                    date=new Date();
                    details+="\n"+note+"\t-"+money+"\t"+sdf.format(date)+"\t"+balance;
                    System.out.println(details);
                    break;
                case "4":
                    String choice="";
                    while(true){
                        System.out.println("你确定要退出吗？y/n");
                        choice=scanner.next();
                        if("y".equals(choice)||"n".equals(choice)){
                            break;
                        }
                    }
                    if(choice.equals("y")){
                        loop=false;
                    }

                    break;
                default:
                    System.out.println("菜单选择有误，请重新选择");
            }
        }while(loop);
        System.out.println("---退出了零钱通项目---");
        }
    }

